package com.bokee.archerwq.lab.socket.serverviapool;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;

import com.bokee.archerwq.lab.thread.mythreadpool.Executor;

public class Server {

	private static Logger logger = Logger.getLogger("Server");

	public Server() throws IOException {
		super();
	}

	public static void main(String[] args) {
		try {
			logger.info("Try listening on port 19999 ...");
			ServerSocket listener = new ServerSocket(19999);
			System.out.println("OK!");

			Executor executor = new Executor(2);

			while (true) {
				Socket processor = listener.accept();
				logger.info("A connection come.");
				MyTask task = new MyTask(processor);
				logger.info("Thread " + MyTask.threadCount + " start!");
				executor.execute(task);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
